﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace BF
{
    public class DictionaryRI<TKey, TValue> : CollectRecycleItem2<Dictionary<TKey, TValue>, KeyValuePair<TKey, TValue>>,
                                              IDictionary<TKey, TValue>,
                                              IDictionary,
                                              IReadOnlyCollection<KeyValuePair<TKey, TValue>>,
                                              IReadOnlyDictionary<TKey, TValue>
    {
        protected IDictionary _iDictionary;

        public TValue this[TKey key] { get => Value[key]; set => Value[key] = value; }

        object IDictionary.this[object key] { get => _iDictionary[key]; set => _iDictionary[key] = value; }

        public Dictionary<TKey, TValue>.KeyCollection Keys => Value.Keys;

        public Dictionary<TKey, TValue>.ValueCollection Values => Value.Values;

        ICollection IDictionary.Keys => Value.Keys;

        ICollection<TKey> IDictionary<TKey, TValue>.Keys => Value.Keys;

        IEnumerable<TKey> IReadOnlyDictionary<TKey, TValue>.Keys => Value.Keys;

        IEnumerable<TValue> IReadOnlyDictionary<TKey, TValue>.Values => Value.Values;

        ICollection IDictionary.Values => Value.Values;

        ICollection<TValue> IDictionary<TKey, TValue>.Values => Value.Values;

        bool IDictionary.IsFixedSize => _iDictionary.IsFixedSize;


        public DictionaryRI()
        {
            Value = new Dictionary<TKey, TValue>();
            _iDictionary = Value;
        }

        public void Add(TKey key, TValue value)
        {
            Value.Add(key, value);
        }

        public bool ContainsKey(TKey key)
        {
            return Value.ContainsKey(key);
        }

        public bool Remove(TKey key)
        {
            return Value.Remove(key);
        }

        public bool TryGetValue(TKey key, out TValue value)
        {
            return Value.TryGetValue(key, out value);
        }

        void IDictionary.Add(object key, object value)
        {
            _iDictionary.Add(key, value);
        }

        bool IDictionary.Contains(object key)
        {
            return _iDictionary.Contains(key);
        }

        IDictionaryEnumerator IDictionary.GetEnumerator()
        {
            return _iDictionary.GetEnumerator();
        }

        void IDictionary.Remove(object key)
        {
            _iDictionary.Remove(key);
        }
    }
}